home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / swags-z / sorting.swg / 0029_SORT-STR.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  762b  |  30 lines

  1. {
  2. It gets better and better.  The Procedure below is incredibly fast in the
  3. sorting of the Strings in the Arrays!  1.2 sec For 1485 Strings.
  4. }
  5.  
  6. Procedure Sort(item : PFilearr; Last : Integer);
  7. Var
  8.   i, j : Integer;
  9.   span : Integer;
  10. begin
  11.   item^[0] := newstr('                       ');
  12.   span := Last shr 1;  {Span=Last/2}
  13.   While span > 0 do
  14.   begin
  15.   For i := Span to Last - 1 do
  16.   begin
  17.     For j := (i - Span + 1) downto 1 do
  18.     if item^[j]^ <= item^[j + Span]^ then
  19.       j:=1   {to make it quit the j-loop}
  20.     else
  21.     begin {swap Array(j) With Array(j+Span)}
  22.       item^[0] := item^[j];
  23.       item^[j] := item^[j + Span];
  24.       item^[j + Span] := item^[0];
  25.     end;
  26.   end;
  27.   Span := Span shr 1; {Span=Span/2}
  28.   end;
  29. end;
  30.